package cn.iocoder.yudao.module.erp.dal.mysql.purchaseplan;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.purchaseplan.vo.PurchasePlanPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.purchaseplan.PurchasePlanDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.io.Serializable;

/**
 * 采购计划 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface PurchasePlanMapper extends BaseMapperX<PurchasePlanDO> {

    default PageResult<PurchasePlanDO> selectPage(PurchasePlanPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PurchasePlanDO>()
                .likeIfPresent(PurchasePlanDO::getPlanName, reqVO.getPlanName())
                .eqIfPresent(PurchasePlanDO::getPlanNo, reqVO.getPlanNo())
                .eqIfPresent(PurchasePlanDO::getPurchaseType, reqVO.getPurchaseType())
                .eqIfPresent(PurchasePlanDO::getApplicationDepartmentId, reqVO.getApplicationDepartmentId())
                .eqIfPresent(PurchasePlanDO::getBudgetDepartmentId, reqVO.getBudgetDepartmentId())
                .eqIfPresent(PurchasePlanDO::getApplicantId, reqVO.getApplicantId())
                .eq(PurchasePlanDO::getDeleted,0)
                .orderByDesc(PurchasePlanDO::getId));
    }

    default int deleteById(Serializable id) {
        LambdaUpdateWrapper<PurchasePlanDO> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(PurchasePlanDO::getId, id)
                .set(PurchasePlanDO::getDeleted,1);
        return this.update(updateWrapper);
    }

}